﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Solidorbrazedturningtoolno7groovingandcutoffdesign2
    {
        public static void _Solidorbrazedturningtoolno7groovingandcutoffdesign2(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数

            double oal = 38.43;
            double h = 7.28;
            double b = 7.23;
            double lpr = 20.3;
            double cdx = 9.07;
            double cw = 3.6;
            double wf = 7.17;
            double kapr = 90;
            double ral = 2;
            double lh = 15.74;
            double s = 1.87;
            double hea1 = 45;
            double hea2 = 37;


            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal, v1.Y);
            Vector2 v3 = new Vector2(v2.X - cdx / 15.117, v2.Y - s);
            Vector2 v4 = new Vector2(v3.X - lh / 14.849, v1.Y - h);
            Vector2 v5 = new Vector2(v1.X, v1.Y - h);
            Vector2 v6 = new Vector2(v2.X - cdx / 1.372, v2.Y - cdx / 4.956);
            Vector2 v7 = new Vector2(v6.X, v6.Y - s / 1.169);
            Vector2 v8 = new Vector2(v2.X - cdx / 1.035, v1.Y);
            Vector2 v9 = new Vector2(v8.X, v5.Y);
            Vector2 v30 = new Vector2(v2.X - lpr, v1.Y);
            Vector2 v31 = new Vector2(v2.X + h, v2.Y);

            Vector2 v12 = new Vector2(v5.X, v5.Y - oal / 2);
            Vector2 v13 = new Vector2(v12.X, v12.Y - b);
            Vector2 v14 = new Vector2(v2.X, v12.Y - wf);
            Vector2 v15 = new Vector2(v14.X - cdx, v14.Y + cdx * Math.Tan(ral * pi / 180));
            Vector2 v16 = new Vector2(v14.X, v14.Y + cw);
            Vector2 v17 = new Vector2(v15.X, v16.Y - cdx * Math.Tan(ral * pi / 180));
            Vector2 v18 = new Vector2(v9.X, v16.Y - (v16.X - v9.X) * Math.Tan(ral * pi / 180));
            Vector2 v19 = new Vector2(v18.X - (v12.Y - v18.Y) / Math.Tan(hea1 * pi / 180), v12.Y);
            Vector2 v20 = new Vector2(v18.X, v14.Y + (v16.Y - v18.Y));
            Vector2 v21 = new Vector2(v20.X - (v20.Y - v13.Y) / Math.Tan(hea2 * pi / 180), v13.Y);
            Vector2 v22 = new Vector2(v14.X - lh, v12.Y);
            Vector2 v23 = new Vector2(v22.X, v13.Y);
            Vector2 v10 = new Vector2(v21.X, v8.Y);
            Vector2 v11 = new Vector2(v10.X, v9.Y);
            Vector2 v24 = new Vector2(v6.X, v16.Y - (v16.X - v6.X) * Math.Tan(ral * pi / 180));
            Vector2 v25 = new Vector2(v24.X, v14.Y + (v16.Y - v24.Y));
            Vector2 v26 = new Vector2(v18.X + cdx / 16.796, v18.Y - cw / 12.414);
            Vector2 v27 = new Vector2(v26.X + cdx / 1.186, v16.Y - cw / 7.66);
            Vector2 v28 = new Vector2(v27.X, v14.Y + cw / 7.66);
            Vector2 v29 = new Vector2(v26.X, v20.Y + cw / 12.414);
            Vector2 v32 = new Vector2(v30.X, v12.Y - b / 2);
            Vector2 v33 = new Vector2(v22.X, v32.Y);


            //作图
            LwPolyline line1 = new LwPolyline();
            line1.Vertexes.Add(new LwPolylineVertex(v3));
            line1.Vertexes.Add(new LwPolylineVertex(v7));
            line1.Vertexes.Add(new LwPolylineVertex(v6));
            line1.Vertexes.Add(new LwPolylineVertex(v2));
            line1.Vertexes.Add(new LwPolylineVertex(v3));
            line1.Vertexes.Add(new LwPolylineVertex(v4));
            line1.Vertexes.Add(new LwPolylineVertex(v5));
            line1.Vertexes.Add(new LwPolylineVertex(v1));
            line1.Vertexes.Add(new LwPolylineVertex(v8));
            line1.Vertexes.Add(new LwPolylineVertex(v6));
            line1.Vertexes.Add(new LwPolylineVertex(v8));
            line1.Vertexes.Add(new LwPolylineVertex(v9));
            line1.Vertexes.Add(new LwPolylineVertex(v11));
            line1.Vertexes.Add(new LwPolylineVertex(v10));
            fun.PolyFill(dxf, line1, 0.2, contour);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v18));
            line2.Vertexes.Add(new LwPolylineVertex(v19));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v13));
            line2.Vertexes.Add(new LwPolylineVertex(v21));
            line2.Vertexes.Add(new LwPolylineVertex(v20));
            line2.Vertexes.Add(new LwPolylineVertex(v21));
            line2.Vertexes.Add(new LwPolylineVertex(v23));
            line2.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, line2, 0.2, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v24));
            line3.Vertexes.Add(new LwPolylineVertex(v25));
            line3.Vertexes.Add(new LwPolylineVertex(v15));
            line3.Vertexes.Add(new LwPolylineVertex(v17));
            line3.Vertexes.Add(new LwPolylineVertex(v16));
            line3.Vertexes.Add(new LwPolylineVertex(v14));
            line3.Vertexes.Add(new LwPolylineVertex(v15));
            fun.PolyFill(dxf, line3, 0.2, contour);

            Line line7 = new Line(v18, v26);
            line7.Layer = refin;
            line7.Linetype = Linetype.Dashed;
            line7.LinetypeScale = 5;
            dxf.AddEntity(line7);

            Line line8 = new Line(v26, v27);
            line8.Layer = refin;
            line8.Linetype = Linetype.Dashed;
            line8.LinetypeScale = 5;
            dxf.AddEntity(line8);

            Line line9 = new Line(v27, v28);
            line9.Layer = refin;
            line9.Linetype = Linetype.Dashed;
            line9.LinetypeScale = 5;
            dxf.AddEntity(line9);

            Line line10 = new Line(v28, v29);
            line10.Layer = refin;
            line10.Linetype = Linetype.Dashed;
            line10.LinetypeScale = 5;
            dxf.AddEntity(line10);

            Line line11 = new Line(v29, v20);
            line11.Layer = refin;
            line11.Linetype = Linetype.Dashed;
            line11.LinetypeScale = 5;
            dxf.AddEntity(line11);

            fun.drawcircle(dxf, v2, 1, 0.02, dimensioning);

            fun.drawcircle(dxf, v14, 1, 0.02, dimensioning);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v2));
            line12.Vertexes.Add(new LwPolylineVertex(v31));
            fun.PolyFill(dxf, line12, 0.02, dimensioning);


            //坐标系
            fun.Axis(dxf, v5, 90, 180, "Y", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v30, 90, 180, "Y", "Z", "MCS", 0.5, 2, 0);

            fun.Axis(dxf, v12, -90, 180, "X", "Z", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v32, -90, 180, "X", "Z", "MCS", 0.5, 2, 0);




            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;



            fun.dimrot1(dxf, v1, v5, 90, h, 1, height, arrowsize, exline, "H", "", "");

            fun.dimrot1(dxf, v2, v4, -90, h, 1, height, arrowsize, exline, "HF", "", "");

            //2
            fun.dimrot1(dxf, v12, v13, 90, h, 1, height, arrowsize, exline, "B", "", "");

            fun.dimrot1(dxf, v22, v33, 90, h * 1.5, 1, height, arrowsize, exline, "=", "", "");

            fun.dimrot1(dxf, v23, v33, 90, h * 1.5, 1, height, arrowsize, exline, "=", "", "");

            fun.dimrot1(dxf, v14, v15, 180, h, 1, height, arrowsize, exline, "CDX", "", "");

            fun.dimrot1(dxf, v14, v23, 180, h * 1.5, 1, height, arrowsize, exline, "LH", "", "");

            fun.dimrot1(dxf, v14, v13, 180, h * 3, 1, height, arrowsize, exline, "OAL,LF", "", "");

            fun.dimrot1(dxf, v14, v32, 180, h * 2.5, 1, height, arrowsize, exline, "LPR,LTA", "", "");

            fun.dimrot1(dxf, v14, v16, -90, h, 1, height, arrowsize, exline, "CW", "", "");

            fun.dimrot1(dxf, v32, v14, -90, h * 3, 1, height, arrowsize, exline, "WTA", "", "");

            fun.dimrot1(dxf, v19, v14, -90, h * 3.5, 1, height, arrowsize, exline, "WF", "", "");

            fun.jdbz2(dxf, new Line(v14, fun.Polar(v14, 0 * pi / 180, 0.1)), new Line(v14, fun.Polar(v14, kapr * pi / 180, 0.1)), h * 2.5, height, arrowsize, exline, "KAPR", "", "");

            fun.jdbz2(dxf, new Line(v16, fun.Polar(v16, 180 * pi / 180, 0.1)), new Line(v16, fun.Polar(v16, (ral - 180) * pi / 180, 0.1)), cdx * 0.8, height, arrowsize, exline, "RAL", "", "");

            fun.jdbz2(dxf, new Line(v14, fun.Polar(v14, (-ral + 180) * pi / 180, 0.1)), new Line(v14, fun.Polar(v14, 180 * pi / 180, 0.1)), cdx * 0.8, height, arrowsize, exline, "RAR", "", "");

            fun.jdbz2(dxf, new Line(v19, fun.Polar(v19, (-hea1 + 180) * pi / 180, 0.1)), new Line(v19, fun.Polar(v19, 180 * pi / 180, 0.1)), cdx / 2, height, arrowsize, exline, "HEA_1", "", "");

            fun.jdbz2(dxf, new Line(v21, fun.Polar(v21, 180 * pi / 180, 0.1)), new Line(v21, fun.Polar(v21, (-180 + hea2) * pi / 180, 0.1)), cdx / 2, height, arrowsize, exline, "HEA_2", "", "");

            fun.jt(dxf, new Vector2(v14.X + oal / 3.72, v14.Y - h / 0.428), 180, 5, height, "FDP");

            fun.jt(dxf, new Vector2(v12.X + oal / 6, v12.Y), 115, 5, height, "CCMS");

            fun.jt(dxf, new Vector2(v31.X - 0.3, v31.Y), 90, 5, height, "HTA");

            fun.text1(dxf, new Vector2(v2.X, v2.Y + h / 5.433), 90, "CRP");

            fun.text1(dxf, new Vector2(v14.X + cdx / 14.629, v14.Y - h / 2.19), 90, "CRP");



            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}